import java.awt.BorderLayout;

import javax.swing.JFrame;

import engine.Engine;
import engine.Util;


public class Launcher {
	public static int log_level = 0;

	public static void main(String[] args) {
		System.setProperty("sun.java2d.translaccel", "true");
		
		parseArgs(args);
		
		Engine engine = Engine.getInstance();
		engine.setLogLevel(log_level);
		engine.initializeConfiguration();
		engine.initializeGraphics();
		
		String windowTitle = Engine.NAME + " (Release: " + Engine.RELEASE + ", Serial Number: " + Engine.SERIAL + ") " + " by " + Engine.AUTHOR;
		JFrame app = new JFrame(windowTitle);
		app.getContentPane().add(engine.getMainPanel(), BorderLayout.CENTER);
		app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		app.pack();
		app.setResizable(false);
		app.setVisible(true);
	}

	private static void parseArgs(String[] args) {
		if (args == null || args.length < 1) {
			return;
		}
		
		String[] tokens;
		
		for (int i = 0; i < args.length; i++) {
			tokens = args[i].split("=");
			
			if (tokens == null || tokens.length < 2) {
				continue;
			}
			
			if (tokens[0].trim().equals("log_level")) {
				log_level = Util.parseInt(tokens[1]);
			}
		}
	}

}